/**
 * 
 */
package vlms.junit;

import static org.junit.Assert.*;

import java.sql.SQLException;

import javax.xml.soap.SOAPException;

import org.junit.Test;

import vlms.bean.Account;
import vlms.bean.Cart;
import vlms.bean.Movie;
import vlms.bean.Person;
import vlms.bean.PremiumCustomer;
import vlms.bean.SimpleCustomer;
import vlms.service.VLMSService;
import vlms.util.DateConvert;
import vlms.util.JDBCConnectionDriver;
import wrapper.CartMovie;
import wrapper.PersonPC;
import wrapper.PersonSC;

/**
 * @author Dell1
 *
 */
public class VLMSUnitTC {

	static {
		try {
			new JDBCConnectionDriver("com.mysql.jdbc.Driver", "jdbc:mysql://localhost:3306/vlmsdb", "root", "root", 100);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	VLMSService vlms = new  VLMSService();
	/**
	 * Test method for {@link vlms.service.VLMSService#deletePremiumCustomer(java.lang.String)}.
	 */
	@Test
	public void testDeletePremiumCustomer() {
		System.out.println("Executing testDeletePremiumCustomer");
		String result = new String();
		Person person = new Person(13, "a1121111@s.com","a","s","a","San Jose","CA","95112", "SC","VISA","1234123412341234",123);
		Account account = new Account("Amitsabyd", "Password@123",1);
		try {
			vlms.createPremiumCustomer(account, person);
			result = vlms.deletePremiumCustomer(String.valueOf(person.getPersonid()));
			assertTrue(result.equals("Premium Customer successfully deleted from the system"));
		} catch (Exception e) {
			System.out.println("Exception occured in the test case testDeletePremiumCustomer : "+e.getMessage());
			e.printStackTrace();
		}
	}

	/**
	 * Test method for {@link vlms.service.VLMSService#deleteSimpleCustomer(java.lang.String)}.
	 */
	@Test
	public void testDeleteSimpleCustomer() {
		System.out.println("Executing testDeleteSimpleCustomer");
		String result = new String();
		Person person = new Person(13, "a1121111@s.com","a","s","a","San Jose","CA","95112", "SC","VISA","1234123412341234",123);
		Account account = new Account("Amitsabyd", "Password@123",1);
		try {
			vlms.createPremiumCustomer(account, person);
			result = vlms.deleteSimpleCustomer(String.valueOf(person.getPersonid()));
			assertTrue(result.equals("Simple Customer successfully deleted from the system"));
		} catch (Exception e) {
			System.out.println("Exception occured in the test case testDeleteSimpleCustomer : "+e.getMessage());
			e.printStackTrace();
		}
	}

	/**
	 * Test method for {@link vlms.service.VLMSService#createMovie(vlms.bean.Movie)}.
	 */
	@Test
	public void testCreateMovie() {
		System.out.println("Executing testCreateMovie");
		String result = new String();
		Movie movie = new Movie(1, "Harry Potter","20th Centuary FOX",DateConvert.convertStringToUtilDate("2009-09-09"),2,"English",3);
		//Account account = new Account("Amitsabyd", "Password@123",1);
		try {
			
			result =vlms.createMovie(movie);
			assertTrue(result.equals("Movie successfully created in the system"));
		} catch (Exception e) {
			System.out.println("Exception occured in the test case testCreateMovie : "+e.getMessage());
			e.printStackTrace();
		}	}

	/**
	 * Test method for {@link vlms.service.VLMSService#deleteMovie(java.lang.String)}.
	 */
	@Test
	public void testDeleteMovie() {
		System.out.println("Executing testDeleteMovie");
		String result = new String();
		Movie movie = new Movie(0, "Harry Potter","20th Centuary FOX",DateConvert.convertStringToUtilDate("2011-02-15"),2,"NEW",3);
		//Account account = new Account("Amitsabyd", "Password@123",1);
		try {
			vlms.createMovie(movie);
			result = vlms.deleteMovie(String.valueOf(movie.getMovieid()));
			assertTrue(result.equals("Movie successfully deleted from the system"));
		} catch (Exception e) {
			System.out.println("Exception occured in the test case testDeleteMovie : "+e.getMessage());
			e.printStackTrace();
		}
	}

	/**
	 * Test method for {@link vlms.service.VLMSService#searchPersonByMemNumber(java.lang.String)}.
	 */
	@Test
	public void testSearchPersonByMemNumber() {
		System.out.println("Executing testSearchPersonByMemNumber");
		String result = new String();
		PersonPC ppc=new PersonPC();
		PersonSC psc=new PersonSC();
		
		try {
//			if()
//			result = vlms.searchPersonByMemNumber(String.valueOf(ppc.getMembershipno()));
//			else()
//		    result = vlms.searchPersonByMemNumber(String.valueOf(psc.getMembershipno()));

			assertTrue(result.equals("Sreach Person by membershipnumber successfully done"));
		} catch (Exception e) {
			System.out.println("Exception occured in the test case searchPersonByMemNumber : "+e.getMessage());
			e.printStackTrace();
		}
	}

	/**
	 * Test method for {@link vlms.service.VLMSService#retrieveIssuedMoviesByMemNumber(java.lang.String)}.
	 */

	@Test
	public void testRetrieveIssuedMoviesByMemNumber() throws SOAPException {
		
		Movie movie = new Movie(1,"Baby's Day Out","20th Century Fox",DateConvert.convertStringToUtilDate("2009-09-09"), 5, "ENGLISH", 70);
		Person person = new Person();
		String[] result;
//		vlms.createMovie(movie);
		vlms.addMovieInCart(String.valueOf(movie.getMovieid()), String.valueOf(1));
		vlms.checkoutMovie(String.valueOf(1));
		result = vlms.retrieveIssuedMoviesByMemNumber("200-00-001");
		assertNotNull(result[0]);
		System.out.println("Result"+ result[0]);
		fail("Not yet implemented");
	}


	/**
	 * Test method for {@link vlms.service.VLMSService#changeIssuedMovieStatus(vlms.bean.IssuedMovie)}.
	 */
	@Test
	public void testChangeIssuedMovieStatus() {
		fail("Not yet implemented");
	}

	/**
	 * Test method for {@link vlms.service.VLMSService#listPremiumCustomer()}.
	 */
	@Test
	public void testListPremiumCustomer() {
		System.out.println("Executing testListPremiumCustomer");
		PremiumCustomer[] result;
		try {
			
			result = vlms.listPremiumCustomer();
			assertTrue(result.equals("All premium customer successfully listed"));
		} catch (Exception e) {
			System.out.println("Exception occured in the test case testListPremiumCustomer : "+e.getMessage());
			e.printStackTrace();
		}
	}

	/**
	 * Test method for {@link vlms.service.VLMSService#listSimpleCustomer()}.
	 */
	@Test
	public void testListSimpleCustomer() {
		System.out.println("Executing testListSimpleCustomer");
		SimpleCustomer[] result;
		try {
			
			result = vlms.listSimpleCustomer();
			assertTrue(result.equals("All simple customer successfully listed"));
		} catch (Exception e) {
			System.out.println("Exception occured in the test case testListSimpleCustomer : "+e.getMessage());
			e.printStackTrace();
		}
	}

	/**
	 * Test method for {@link vlms.service.VLMSService#listAllMovies()}.
	 */
	@Test
	public void testListAllMovies() {
		System.out.println("Executing testListAllMovies");
		Movie[] result;
		try {
			result = vlms.listAllMovies();
			assertTrue(result.equals("All movies successfully listed"));
		} catch (Exception e) {
			System.out.println("Exception occured in the test case testListAllMovies : "+e.getMessage());
			e.printStackTrace();
		}
	}

	/**
	 * Test method for {@link vlms.service.VLMSService#listAllPersons()}.
	 */
	@Test
	public void testListAllPersons() {
		System.out.println("Executing testListAllPersons");
		Person[] result;
		try {
			result = vlms.listAllPersons();
			assertTrue(result.equals("All Persons successfully listed"));
		} catch (Exception e) {
			System.out.println("Exception occured in the test case testListAllPersons : "+e.getMessage());
			e.printStackTrace();
		}
	}

	/**
	 * Test method for {@link vlms.service.VLMSService#updateMovie(vlms.bean.Movie)}.
	 */
	@Test
	public void testUpdateMovie() {
		System.out.println("Executing testUpdateMovie");
		String result = new String();
		Movie movie = new Movie(1, "Harry Potter","20th Centuary FOX",DateConvert.convertStringToUtilDate("2009-09-09"),2,"English",3);
		//Account account = new Account("Amitsabyd", "Password@123",1);
		try {
			vlms.createMovie(movie);
			result = vlms.updateMovie(movie);
			assertTrue(result.equals("Movie successfully updated in the system"));
		} catch (Exception e) {
			System.out.println("Exception occured in the test case testUpdateMovie : "+e.getMessage());
			e.printStackTrace();
		}
	}

	/**
	 * Test method for {@link vlms.service.VLMSService#searchPerson(vlms.bean.Person)}.
	 */
	@Test
	public void testSearchPerson() {
		System.out.println("Executing testSearchPerson");
		String[] result;
		Person per = new Person(13, "a1121111@s.com","a","s","a","San Jose","CA","95112", "SC","VISA","1234123412341234",123);
		try {
			result = vlms.searchPerson(per);
			assertTrue(result.equals(" Person successfully searched"));
		} catch (Exception e) {
			System.out.println("Exception occured in the test case testSearchPerson : "+e.getMessage());
			e.printStackTrace();
		}
	}

	/**
	 * Test method for {@link vlms.service.VLMSService#searchMovie(vlms.bean.Movie)}.
	 */
	@Test
	public void testSearchMovie() {
		System.out.println("Executing testSearchMovie");
		Movie[] result;
		Movie mov = new Movie(1, "Harry Potter","20th Centuary FOX",DateConvert.convertStringToUtilDate("2009-09-09"),2,"English",3);

		try {
			result = vlms.searchMovie(mov);
			assertTrue(result.equals(" Movie successfully searched"));
		} catch (Exception e) {
			System.out.println("Exception occured in the test case testSearchMovie : "+e.getMessage());
			e.printStackTrace();
		}
	}

	/**
	 * Test method for {@link vlms.service.VLMSService#retrieveSimpleCustomerByPersonId(java.lang.String)}.
	 */
	@Test
	public void testRetrieveSimpleCustomerByPersonId() {
		fail("Not yet implemented");
	}

	/**
	 * Test method for {@link vlms.service.VLMSService#retrievePremiumCustomerByPersonId(java.lang.String)}.
	 */
	@Test
	public void testRetrievePremiumCustomerByPersonId() {
		fail("Not yet implemented");
	}

	/**
	 * Test method for {@link vlms.service.VLMSService#retrieveIssuedMoviesByPersonId(java.lang.String)}.
	 */
	@Test
	public void testRetrieveIssuedMoviesByPersonId() {
		fail("Not yet implemented");
	}

	/**
	 * Test method for {@link vlms.service.VLMSService#retrieveMovieById(java.lang.String)}.
	 */
	@Test
	public void testRetrieveMovieById() {
		System.out.println("Executing testRetrivedMoviesById");
		Movie result=new Movie();;
		Movie mov = new Movie(1, "Harry Potter","20th Centuary FOX",DateConvert.convertStringToUtilDate("2009-09-09"),2,"English",3);

		try {
			result = vlms.retrieveMovieById(String.valueOf(mov.getMovieid()));
			assertTrue(result.equals("Movie successfully retrived"));
		} catch (Exception e) {
			System.out.println("Exception occured in the test case testRetrieveMovieById : "+e.getMessage());
			e.printStackTrace();
		}
	}

	/**
	 * Test method for {@link vlms.service.VLMSService#retrievePersonByEmail(java.lang.String)}.
	 */
	@Test
	public void testRetrievePersonByEmail() {
		Person person = new Person(1,"virtivora@gmail.com","Virti","Vora","210 N 1st Street","San Jose","CA","95112","PC","Visa","3434576577345324",123);
		Person result;
		Account account = new Account("virtivora", "Password@123", 1);
		vlms.createPremiumCustomer(account, person);
		result = vlms.retrievePersonByEmail("virtivora@gmail.com");
		assertNotNull(result);
	}

	/**
	 * Test method for {@link vlms.service.VLMSService#retrievePersonsByMovieId(java.lang.String)}.
	 */
	@Test
	public void testRetrievePersonsByMovieId() {
		fail("Not yet implemented");
	}

	/**
	 * Test method for {@link vlms.service.VLMSService#clearFine(java.lang.String)}.
	 */
	@Test
	public void testClearFine() {
		System.out.println("Executing testCLearFine");
		String result = new String();
		Person person = new Person(14, "a21111@s.com","a1","s1","a1","San Jose","CA","95112", "PC","VISA","1234123412341988",133);
		try {
			result = vlms.clearFine(String.valueOf(person.getPersonid()));
			assertTrue(result.equals("Clear Fine Successful"));
		} catch (Exception e) {
			System.out.println("Exception occured in the test case testClearFine : "+e.getMessage());
			e.printStackTrace();
		}
	}

	/**
	 * Test method for {@link vlms.service.VLMSService#viewFine(java.lang.String)}.
	 */
	@Test
	public void testViewFine() {
		System.out.println("Executing testViewFine");
		String result = new String();
		Person person = new Person(13, "a1121111@s.com","a","s","a","San Jose","CA","95112", "SC","VISA","1234123412341234",123);

		try {
			result = vlms.viewFine(String.valueOf(person.getPersonid()));
			assertTrue(result.equals("View Fine successful"));
		} catch (Exception e) {
			System.out.println("Exception occured in the test case testDeleteMovie : "+e.getMessage());
			e.printStackTrace();
		}
	}

	/**
	 * Test method for {@link vlms.service.VLMSService#createPremiumCustomer(vlms.bean.Account, vlms.bean.Person)}.
	 */
	@Test
	public void testCreatePremiumCustomer() {
		System.out.println("Executing testCreatePremiumCustomer");
		String result = new String();
		Person person = new Person(14, "a21111@s.com","a1","s1","a1","San Jose","CA","95112", "PC","VISA","1234123412341988",133);
		Account account = new Account("Amit", "Password@1234",6);
		try {
			
			result = vlms.createPremiumCustomer(account, person);
			assertTrue(result.equals("Premium Customer successfully created in the system"));
		} catch (Exception e) {
			System.out.println("Exception occured in the test case testCreatePremiumCustomer : "+e.getMessage());
			e.printStackTrace();
		}
	}

	/**
	 * Test method for {@link vlms.service.VLMSService#createSimpleCustomer(vlms.bean.Account, vlms.bean.Person)}.
	 */
	@Test
	public void testCreateSimpleCustomer() {
		System.out.println("Executing testCreateSimpleCustomer");
		String result = new String();
		Person person = new Person(15, "s21111@s.com","s1","a1","s1","San Jose","CA","95112", "SC","VISA","1234123412341899",143);
		Account account = new Account("Stuti", "Password@1245",7);
		try {
			
			result = vlms.createSimpleCustomer(account, person);
			assertTrue(result.equals("Simple Customer successfully created in the system"));
		} catch (Exception e) {
			System.out.println("Exception occured in the test case testCreateSimpleCustomer : "+e.getMessage());
			e.printStackTrace();
		}
	}


	/**
	 * Test method for {@link vlms.service.VLMSService#logIn(vlms.bean.Account)}.
	 */
	@Test
	public void testLogIn() {
		System.out.println("Executing testLogIn");
		Account result = new Account();
		
		Account account = new Account("Stuti", "Password@1245",7);
		try {
			
			result = vlms.logIn(account);
			assertTrue(result.equals("Simple Customer successfully created in the system"));
		} catch (Exception e) {
			System.out.println("Exception occured in the test case testCreateSimpleCustomer : "+e.getMessage());
			e.printStackTrace();
		}
	}

	/**
	 * Test method for {@link vlms.service.VLMSService#retrieveIssuedMovieByPersonId(java.lang.String)}.
	 */
	@Test
	public void testRetrieveIssuedMovieByPersonId() {
		fail("Not yet implemented");
	}

	/**
	 * Test method for {@link vlms.service.VLMSService#retrieveAllMoviesByPersonId(java.lang.String)}.
	 */
	@Test
	public void testRetrieveAllMoviesByPersonId() {
		fail("Not yet implemented");
	}

	/**
	 * Test method for {@link vlms.service.VLMSService#retrievePersonById(java.lang.String)}.
	 */
	@Test
	public void testRetrievePersonById() {
		fail("Not yet implemented");
	}

	/**
	 * Test method for {@link vlms.service.VLMSService#updateMember(vlms.bean.Account, vlms.bean.Person)}.
	 */
	@Test
	public void testUpdateMember() {
		System.out.println("Executing testUpdateMember");
		String result = new String();
		Person person = new Person(15, "s21111@s.com","s1","a1","s1","San Jose","CA","95112", "SC","VISA","1234123412341899",143);
		Account account = new Account("Stuti", "Password@1245",7);
		try {
			
			result = vlms.updateMember(account,person);
			assertTrue(result.equals("Member successfully updated in the system"));
		} catch (Exception e) {
			System.out.println("Exception occured in the test case testUpdateMember : "+e.getMessage());
			e.printStackTrace();
		}
	}

	/**
	 * Test method for {@link vlms.service.VLMSService#retrieveMovies(vlms.bean.Movie)}.
	 */
	@Test
	public void testRetrieveMovies() {
		System.out.println("Executing testRetrivedMovies");
		Movie[] result;
		Movie mov = new Movie(1, "Harry Potter","20th Centuary FOX",DateConvert.convertStringToUtilDate("2009-09-09"),2,"English",3);

		try {
			result = vlms.retrieveMovies(mov);
			assertTrue(result.equals("Movies successfully retrived"));
		} catch (Exception e) {
			System.out.println("Exception occured in the test case testRetrieveMovies : "+e.getMessage());
			e.printStackTrace();
		}
	}

	/**
	 * Test method for {@link vlms.service.VLMSService#checkoutMovie(java.lang.String)}.
	 */
	@Test
	public void testCheckoutMovie() {
		System.out.println("Executing testCheckoutMovies");
		String result;
		Movie mov = new Movie(1, "Harry Potter","20th Centuary FOX",DateConvert.convertStringToUtilDate("2009-09-09"),2,"English",3);

		try {
			result = vlms.checkoutMovie(String.valueOf(mov.getMovieid()));
			assertTrue(result.equals("Movies successfully checked out"));
		} catch (Exception e) {
			System.out.println("Exception occured in the test case testCheckout : "+e.getMessage());
			e.printStackTrace();
		}
	}

	/**
	 * Test method for {@link vlms.service.VLMSService#generateBill(java.lang.String)}.
	 */
	@Test
	public void testGenerateBill() {
		System.out.println("Executing testGenerateBill");
		String[] result;
		Person person = new Person(13, "a1121111@s.com","a","s","a","San Jose","CA","95112", "SC","VISA","1234123412341234",123);

		try {
			result = vlms.generateBill(String.valueOf(person.getPersonid()));
			assertTrue(result.equals("Bill Successfully generated"));
		} catch (Exception e) {
			System.out.println("Exception occured in the test case testGenerateBill : "+e.getMessage());
			e.printStackTrace();
		}
			}

	/**
	 * Test method for {@link vlms.service.VLMSService#viewCart(java.lang.String)}.
	 */
	@Test
	public void testViewCart() {
		System.out.println("Executing testViewCart");
		CartMovie[] result;
		Person person = new Person(13, "a1121111@s.com","a","s","a","San Jose","CA","95112", "SC","VISA","1234123412341234",123);

		try {
			result = vlms.viewCart(String.valueOf(person.getPersonid()));
			assertTrue(result.equals("View Cart Successful"));
		} catch (Exception e) {
			System.out.println("Exception occured in the test case testViewCart : "+e.getMessage());
			e.printStackTrace();
		}
		
			}

	/**
	 * Test method for {@link vlms.service.VLMSService#addMovieInCart(java.lang.String, java.lang.String)}.
	 */
	@Test
	public void testAddMovieInCart() {
		System.out.println("Executing testCheckoutMovies");
		Cart result=new Cart();
		Person person = new Person(13, "a1121111@s.com","a","s","a","San Jose","CA","95112", "SC","VISA","1234123412341234",123);
		Movie mov = new Movie(1, "Harry Potter","20th Centuary FOX",DateConvert.convertStringToUtilDate("2009-09-09"),2,"English",3);

		try {
//			result = vlms.addMovieInCart(String.valueOf(mov.getMovieid()),String.valueOf(person.getPersonid()));
			assertTrue(result.equals("Movie successfully added to cart"));
		} catch (Exception e) {
			System.out.println("Exception occured in the test case testAddMovieInCart : "+e.getMessage());
			e.printStackTrace();
		}
	}

	/**
	 * Test method for {@link vlms.service.VLMSService#deleteMovieFromCart(java.lang.String)}.
	 */
	@Test
	public void testDeleteMovieFromCart() {
		System.out.println("Executing testDeleteMovieFromCart");
		String result;
		Cart cart = new Cart(1,2,3);

		try {
			result = vlms.deleteMovieFromCart(String.valueOf(cart.getCartid()));
			assertTrue(result.equals("Movie successfully deleted from cart"));
		} catch (Exception e) {
			System.out.println("Exception occured in the test case testDeleteMovieFromCart : "+e.getMessage());
			e.printStackTrace();
		}

			}

	/**
	 * Test method for {@link vlms.service.VLMSService#addBalanceToAccount(java.lang.String, java.lang.String)}.
	 */
	@Test
	public void testAddBalanceToAccount() {
		System.out.println("Executing testAddBalanceToAccount");
		String result;
		int amount=30;
		Person person = new Person(15, "s21111@s.com","s1","a1","s1","San Jose","CA","95112", "SC","VISA","1234123412341899",143);

		try {
			result = vlms.addBalanceToAccount(String.valueOf(person.getPersonid()),String.valueOf(amount));
			assertTrue(result.equals("Balance successfully added to account"));
		} catch (Exception e) {
			System.out.println("Exception occured in the test case testAddBalanceToAccount : "+e.getMessage());
			e.printStackTrace();
		}

	}
	




}
